//
//  ViewController.m
//  Layout代码
//
//  Created by hyl on 16/5/16.
//  Copyright © 2016年 hyl. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

-(void)viewDidLoad{
    [super viewDidLoad];
    self.view.translatesAutoresizingMaskIntoConstraints=NO;
    UIView *viewRed=[[UIView alloc]init];
    viewRed.backgroundColor=[UIColor redColor];
    viewRed.translatesAutoresizingMaskIntoConstraints=NO;
    [self.view addSubview:viewRed];
    
    //viewRed.frame=CGRectMake(100, 100, 100, 50);
    NSLayoutConstraint *widthConstraint=[NSLayoutConstraint constraintWithItem:viewRed attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:100];
    [viewRed addConstraint:widthConstraint];
    NSLayoutConstraint *heightConstraint=[NSLayoutConstraint constraintWithItem:viewRed attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual  toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:50];
    [viewRed addConstraint:heightConstraint];
    
    NSLayoutConstraint *leftContraint=[NSLayoutConstraint constraintWithItem:viewRed attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1.0 constant:30];
    [self.view addConstraint:leftContraint];
    NSLayoutConstraint *topConstraint=[NSLayoutConstraint constraintWithItem:viewRed attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:30];
    [self.view addConstraint:topConstraint];
}



@end
